#  返回top数据

from utils import restful


def top_return(models, sum):
    try:
        warn_sum = models.objects.all()
    except Exception as e:
        return restful.params_error(message=e)
        pass
    else:
        warn_list = []
        for map in warn_sum:
            data = {'value': 12, 'name': map.name}
            warn_list.append(data)
        data = sorted(
            warn_list, key=lambda x: x['value'], reverse=True)[:sum]
        return data
